if($.cookie("MYID")){id=$.cookie("MYID")};
//分享提醒判断
function IsPC() {
    var userAgentInfo = navigator.userAgent;
    var Agents = ["Android", "iPhone",
        "SymbianOS", "Windows Phone",
        "iPad", "iPod"];
    var flag = true;
    for (var v = 0; v < Agents.length; v++) {
        if (userAgentInfo.indexOf(Agents[v]) > 0) {
            flag = false;
            break;
        }
    }
    return flag;
};
//返回
var fromeurl=document.referrer;

//返回
$("#goback").click(function(){

    //有来源网址 直接返回 新闻返回涉及到数据更新用cookie判断直接刷新阅读圈
    if((document.referrer&&document.referrer!=(location.href))&&!/sendsharepage/.test(document.referrer)&&!/from=singlemessage|isappinstalled/.test(document.referrer)){

        if($.cookie("newstypeid")){history.go(-1);}//新闻列表页
        else{ //首页
            if(/pulu.html/.test(document.referrer)){
                if(is_weixn()){location.href="http://www.pulu.com/weixin/pulu.html"}
                else{location.href="https://www.pulu.com/weixin/pulu.html"}
            }
            else{
                if($.cookie("reloadPage")=="reloadPage"){
                    $.cookie("reloadPage","");
                    history.go(-3);
                }else{
                    history.go(-1);
                }
            }
        }

    }
    //没有来源网址 去首页
    else{
        if($.cookie("MYID")){
            //有来源网址 可能为转发的新闻列表页
            if(document.referrer){
                //区分经验和问题
                if(/shareexppage.html/.test(document.referrer)&&/from=singlemessage|isappinstalled/.test(document.referrer)){
                    //转发经验
                    if(is_weixn()){location.href="http://www.pulu.com/weixin/pulu.html"}
                    else{location.href="https://www.pulu.com/weixin/pulu.html"}
                }
                else if(/questiondetail.html/.test(document.referrer)&&/from=singlemessage|isappinstalled/.test(document.referrer)){
                    //转发问题
                    if(is_weixn()){location.href="http://www.pulu.com/weixin/pulu.html"}
                    else{location.href="https://www.pulu.com/weixin/pulu.html"}
                }else{
                    history.go(-1);
                }
            }
            //转发链接
            else{
                if(is_weixn()){location.href="http://www.pulu.com/weixin/pulu.html"}
                else{
                    if(!/https/.test(location.href)) {//pc 唯一http网址
                        history.go(-1);
                    }else{
                        location.href="https://www.pulu.com/weixin/pulu.html";
                    }

                }
            }
        }
        else{
            location.href="http://www.pulu.com/weixin/login.html";
        }
    }
});

//去主页
$("#gohome").click(function(){
    if($.cookie("MYID")){
        //清除定位参数
        $.cookie("puluscrollTop","");
        $.cookie("pulucurrentIndex","");
        location.href="http://www.pulu.com/weixin/pulu.html";
    }
    else{
        //只有新闻跳转问题
        if(/newsdetail/.test(location.href)){
            var newsId=(location.href).match(/newsid=[0-9]+/)[0].split("=")[1];
            location.href="http://www.pulu.com/weixin/index.html?newsid="+newsId+"&fromuser="+id;
        }
    }
});
//转发2
$("#sharenews").click(function(){
    if($.cookie("MYID")){
        $("#share_T").css("display","-webkit-box");
    }
    else{
        //只有新闻跳转
        if(/newsdetail/.test(location.href)){
            var newsId=(location.href).match(/newsid=[0-9]+/)[0].split("=")[1];
            //没有用户ID 转发者截取
            var urlnserid=location.href.match(/fromuser=[0-9a-z]+/)[0].split("=")[1];
            location.href="http://www.pulu.com/weixin/index.html?newsid="+newsId+"&fromuser="+urlnserid;
        }
    }
});
$("#gotoshare").click(function(){
    if($.cookie("MYID")){
        $("#share_T").css("display","none");
        if(/shareexppage/.test(location.href)){

            $.cookie("shareexpid",eid);
            $("#share_T").css("display","none");
            if(!typeNum){typeNum=3};
            location.href="sendsharepage.html?type="+typeNum;
        }
        else if(/questiondetail/.test(location.href)){
            $.cookie("sharequeid",qid);
            $("#share_T").css("display","none");
            location.href="sendsharepage.html?type=2";
        }
        else if(/newsdetail/.test(location.href)){
            var newsid= $.cookie("newsid");
            if(/newsid=/.test(location.href)){
                newsid=(location.href).match(/newsid=[0-9]+/)[0].split("=")[1];
            }
            if(newsid){
                if(!$.cookie("sharenewsid")){
                    $.cookie("sharenewsid",newsid);
                }
                $("#share_T").css("display","none");
                location.href="sendsharepage.html?type=1";
            }
        }
    }
    else{
        //只有新闻跳转问题
        if(/newsdetail/.test(location.href)){
            $("#share_T").css("display","none");
            var newsId=(location.href).match(/newsid=[0-9]+/)[0].split("=")[1];
            location.href="http://www.pulu.com/weixin/index.html?newsid="+newsId+"&fromuser="+id;
        }
    }
});
//微信
if(is_weixn()){
    $("#pcimgplace").css("display","none");
    $("#phoneimgplace").css("display","none");
}else{
    if(IsPC()){
        $("#wximgplace").css("display","none");
        $("#phoneimgplace").css("display","none");
    }else{
        $("#wximgplace").css("display","none");
        $("#pcimgplace").css("display","none");
    }
};
$("#sharetowx").click(function(){
    $("#sharenoticpage").css("display","block");
    $("#share_T").css("display","none");
});
$("#sharenoticpage").click(function(){
    $("#sharenoticpage").css("display","none");
});
//关闭选择页
$("#share_T .close").click(function(){
    $("#share_T").css("display","none");
});
//关闭点赞提醒
$("#closealertbtn").click(function(){
    $("#nokeywordalert").css("display","none");
});
//点赞
if(/newsid=/.test(location.href)){
    newsId=(location.href).match(/newsid=[0-9]+/)[0].split("=")[1];
    if($.cookie("thumbsUp")&&newsId==$.cookie("thumbsUp")){
        $("#thumbs-up").css({"background":"url(img/afv.png)no-repeat center","background-size":"24px"});
    }
}
$("#thumbs-up").click(function(){
    console.log(istopnews);//weixinsharenews.js
    //没有点击过 才能继续点击
    if($("#thumbs-up").css("background")){var imgword=$("#thumbs-up").css("background")}
    else{var imgword=$("#thumbs-up").css("backgroundImage")}
    if(!/afv/.test(imgword)){ //没有点击过
        if($.cookie("MYID")){
            if(/newsdetail.html/.test(location.href)){
                if(/newsid=/.test(location.href)){
                    newsId=(location.href).match(/newsid=[0-9]+/)[0].split("=")[1];
                }
            }
            //是否点过赞
            if(!/afv.png/.test($("#thumbs-up").css("background"))){
                //阅读圈或头部滚动进入 //不是系统推荐
                if((/newsShareId/.test(location.href)||$.cookie("newsShareId"))&&!istopnews){
                    if($.cookie("newsShareId")){collectid=$.cookie("newsShareId")}
                    else{collectid=(location.href).match(/newsShareId=[0-9]+/)[0].match(/[0-9]+/)[0];}
                    $.ajax({
                        type:"post",
                        datatype:"json",
                        url:"https://www.pulu.com/webapi/api/puluquestion/AddShareNewsUp",//赞
                        data:{"shareId":collectid,"userId":id},//赞
                        success:function(data){
                            if(data.Message=="成功"){
                                $("#nokeywordalert").css("display","block");
                                $("#thumbs-up").css({"background":"url(img/afv.png)no-repeat center","background-size":"24px"});
                                $.cookie("thumbsUp",newsId);
                            }
                        }
                    })
                }
                //列表页进入
                else{
                    $.ajax({
                        type:"post",
                        url:"https://www.pulu.com/webapi/api/PuluUpdown/AddPulu_updownFromOutpage",
                        data:{"newsid":newsId,"userId":id},
                        success:function(d){
                            console.log("==========点赞返回==========");
                            console.log(d);
                            console.log("============================");
                            if(d.Code==="TRUE"){
                                $("#nokeywordalert").css("display","block");
                                $.cookie("newsShareId", d.Message);
                                $.cookie("sharenewsid",d.Message);//转发页面参数
                                $("#thumbs-up").css({"background":"url(img/afv.png)no-repeat center","background-size":"24px"});
                                $.cookie("thumbsUp",newsId);
                                istopnews=false;//点完赞 转发完成 不是系统推荐
                                console.log(istopnews);
                            }
                        }
                    });
                }
            }
        }
        else{
            //只有新闻跳转问题
            if(/newsdetail/.test(location.href)){
                var newsId=(location.href).match(/newsid=[0-9]+/)[0].split("=")[1];
                location.href="http://www.pulu.com/weixin/index.html?newsid="+newsId+"&fromuser="+id;
            }
        }
    }
    else{console.log("已经点过赞")}
});
//评论 共用问题评论页$("div[id*='givechat']")
$("[id*='givechat']").click(function(){
    if($.cookie("MYID")){
        //新闻
        if(/newsdetail.html/.test(location.href)){
            if(/newsid=/.test(location.href)){
                newsId=(location.href).match(/newsid=[0-9]+/)[0].split("=")[1];
            }
            var shareNewsId="";
            //不是系统推荐
            if(/newsShareId/.test(location.href)&&!istopnews){
                if(((location.href).match(/newsShareId=[0-9]+/)[0].match(/[0-9]+/)[0])!=0){
                    shareNewsId="&shareNewsId="+(location.href).match(/newsShareId=[0-9]+/)[0].match(/[0-9]+/)[0];
                }
            }
            //不是系统推荐
            if(/^[0-9]+$/.test($.cookie("newsShareId"))&&!istopnews){
                if($.cookie("newsShareId")!=0){
                    shareNewsId="&shareNewsId="+$.cookie("newsShareId");
                }
            }
            location.href="comment.html?aid=c"+newsId+shareNewsId;
        }
        //问题
        else if(/questiondetail.html/.test(location.href)){
            if(/qid=/.test(location.href)){
                newsId=(location.href).match(/qid=[0-9]+/)[0].split("=")[1];
            }
            var shareUserId="";
            if($.cookie("fromuser")&&!/fromuser/.test($.cookie("fromuser"))){
                if($.cookie("fromuser")!==id){shareUserId="&shareUserId="+$.cookie("fromuser");}
            }
            if($.cookie("shareUserId")){
                shareUserId="&shareUserId="+$.cookie("shareUserId");
            }
            $.cookie("fromquestiondetial",qid);

            location.href="answerpage.html?id="+id+"&qid="+qid+shareUserId;
        }
        //经验
        else if(/shareexppage/.test(location.href)){
            if(/eid=/.test(location.href)){
                newsId=(location.href).match(/eid=[0-9]+/)[0].split("=")[1];
            }
            location.href="comment.html?aid=c"+newsId+"&fromexp";
        }
    }
    else{
        //只有新闻跳转问题
        if(/newsdetail/.test(location.href)){
            var newsId=(location.href).match(/newsid=[0-9]+/)[0].split("=")[1];
            location.href="http://www.pulu.com/weixin/index.html?newsid="+newsId+"&fromuser="+id;
        }
    }
});